package day4;

import java.util.Scanner;

import org.junit.Test;
import org.junit.experimental.max.MaxCore;

import day3.Student;

public class Demo {
	//方法的调用实例
	public static void main(String[] args) {
		int[] arr = {23, 56, 8, 99, 2};
		int max = max(arr);
		System.out.println(max);
	}
	
	public static int max(int[] arr) {
		int max = arr[0];
		for (int i = 0; i < arr.length; i++) {
			if (arr[i]>max) {
				max = arr[i];
			}
		}
		
		return max;
		
	}
	
	//简易教师信息搜索系统
	@Test	
	public void techerDemo() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入老师的数量：");
		int count = scanner.nextInt();
		Teacher[] teachers = new Teacher[count];
		
		for (int i = 0; i < teachers.length; i++) {
			
			System.out.print("请输入老师的ID：");
			int id = scanner.nextInt();
			System.out.print("请输入老师的姓名：");
			String name = scanner.next();
			System.out.print("请输入老师的年龄：");
			int age = scanner.nextInt();
			System.out.print("请输入老师的任课班级：");
			String className = scanner.next();
			
			Teacher teacher = new Teacher(id, name, age, className);
			//用构造方法直接将将赋的值转给对象
//			teacher.setId(id);
//			teacher.setAge(age); 
//			teacher.setClassName(className);
//			teacher.setName(name);
			teachers[i] = teacher;
			System.out.println(teacher);
			
		}
		for (int i = 0; i < teachers.length; i++) {
			teachers[i].printInfo();
		}
		System.out.println("----------------");
		int type = 1;
		while(type != 0 ) {
		System.out.println("根据id查找请输入1");
		System.out.println("根据name查找请输入2");
		System.out.println("根据age查找请输入3");
		System.out.println("根据className查找请输入4");
		System.out.println("退出查找请输入0");

		System.out.println("----------------");
		type = scanner.nextInt();
		
		switch (type) {
		case 1://根据id查找
			System.out.println("请输入要查找教师id");
			int id = scanner.nextInt();
			boolean isSearchByIdFind = false;
			for (int i = 0; i < teachers.length; i++) {
				Teacher teacher = teachers[i];
				if (teacher.getId() == id) {	
					System.out.println("*************");
					teacher.printInfo();
					System.out.println("*************");
					isSearchByIdFind = true;
				}
			}
			if (isSearchByIdFind == false) {
				System.out.println("*************");
				System.out.println("没有这个教师的信息");
				System.out.println("*************");
			}
			break;
		
		case 2:
			System.out.println("请输入该教师的姓名：");
			String name = scanner.next();
			boolean isSeachNameFind = false;
			
			for (int i = 0; i < teachers.length; i++) {
				Teacher teacher = teachers[i];
				if ((teacher.getName()).equals(name) ) {
					System.out.println("*************");
					teacher.printInfo();
					System.out.println("*************");
					isSeachNameFind = true;
				}
			}
			if (isSeachNameFind == false) {
				System.out.println("*************");
				System.out.println("*没有找到该信息的教师*");
				System.out.println("*************");
			}
			break;
			
		case 3:
			System.out.println("请输入要查找教师年龄");
			int age = scanner.nextInt();
			boolean isSearchByAgeFind = false;
			for (int i = 0; i < teachers.length; i++) {
				Teacher teacher = teachers[i];
				if (teacher.getAge() == age) {	
					System.out.println("*************");
					teacher.printInfo();
					System.out.println("*************");
					isSearchByAgeFind = true;
				}
			}
			if (isSearchByAgeFind == false) {
				System.out.println("*************");
				System.out.println("没有这个教师的信息");
				System.out.println("*************");
			}
			break;
			
		case 4:
			System.out.println("请输入该教师的任课班级：");
			String className = scanner.next();
			boolean isSeachClassFind = false;
			
			for (int i = 0; i < teachers.length; i++) {
				Teacher teacher = teachers[i];
				if ((teacher.getClassName()).equals(className) ) {
					System.out.println("*************");
					teacher.printInfo();
					System.out.println("*************");
					isSeachClassFind = true;
				}
			}
			if (isSeachClassFind == false) {
				System.out.println("*************");
				System.out.println("没有找到该信息的教师");
				System.out.println("*************");
			}
			break;
		default:
			System.out.println("已退出");
			break;
		}
		}
	}
	
	
	@Test
	public void test1() {
		//null可以赋值给所有的引用数据类型
		//引用数据类型的默认值就是null
		
		//The local variable array1 may not have been initialized
				//局部变量要使用必须要赋初值
		
//		int[] array = null;//不想赋值也不想定义长度时可用null
//		int num = array[0];
		
		

		
		
		Teacher teacher = null;
		System.out.println(teacher.getId());
		
	}
	
	@Test
	public void test2() {
		Teacher teacher = new Teacher();
		System.out.println(teacher.getId());
		//student.null是不会报NullPointerException,只有null.属性或null。方法
		//且只有为数组时null[i]才会报空指针异常
		Teacher[ ] array = new Teacher[3] ;
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
}
